const express = require("express");
const router = express.Router();
const service = require("../model/room");

router.post("/create", (req, res) => {
    service.create(req.body.name, req.body.creatorId, data => {
        res.send(data)
            .status(200)
            .end();
        console.log("创建了一个room: " + req.body.name);
    });
});

router.post("/addMember", (req, res) => {
    service.addMember(req.body.roomId, req.body.memberId, data => {
        res.send(data)
            .status(200)
            .end();        
    });
});

router.post("/findUserRooms", (req, res) => [
    service.findUserRooms(req.body.userId, data => {
        res.send(data)
            .status(200)
            .end();
    })
]);

router.post("/enter", (req, res) => {
    service.enter(req.body.roomId, data => {
        res.send(data)
            .status(200)
            .end();
    });
});

module.exports = router;
